Skip to content

perf(examples): async_date_timerfd on the new stdlib time APIs + README#92

Draft
enghitalo wants to merge 1 commit into
mainfrom
feat/async-date-timerfd-stdlib
Draft

perf(examples): async_date_timerfd on the new stdlib time APIs + README#92
enghitalo wants to merge 1 commit into
mainfrom
feat/async-date-timerfd-stdlib

Conversation

@enghitalo

Copy link
Copy Markdown
Owner

Summary

Refactors examples/async_date_timerfd as if the three upstream V PRs were merged, and adds a README with a mermaid flow of the whole model.

  • rebuild() collapses to 3 lines: time.unix_now() (~2 ns) + time.update_http_header (~2 ns within the same minute; full reformat only on day rollover). The ~55 lines of hand-rolled bucket logic, digit writer and name tables moved to vlib, oracle-tested there.
  • import time brings the timerfd declarations: no local fn C. decls, typed C.itimerspec instead of a raw [4]i64, and the tick drains into a named u64 expiration count.
  • README documents the one-loop/two-event-kinds model (mermaid), the cached line's byte layout, the cost table and the contrast with date_header/efficient_date.
  • Net: −132/+65 in the example before the README.

Depends on (do not merge until these land in V master)

The example is not in the CI matrices, so this cannot break CI either way — the draft state is about not landing an example that requires an unreleased toolchain.

Verification (patched local toolchain)

  • 3/3 tests, including one pinning date_line_len == 6 + time.http_header_len + 2 (the fixed-array size stays a literal: cross-module const arithmetic in a fixed-array size trips the checker in _test.v builds — V bug worth filing separately).
  • -prod build clean; live server: Date advanced 12:05:15 → 12:05:17 under zero load.
  • v check-md clean on the README.

🤖 Generated with Claude Code

Refactor the example as if vlang/v#27639/#27641/#27642 were merged
(they are open; V must be built from those branches until then):

- rebuild() is now 3 lines: time.unix_now() (~2 ns wall-clock read) +
  time.update_http_header (in-place incremental refresh, ~2 ns within
  the same minute; calendar math only on day rollover). The hand-rolled
  bucket logic, digit writer and name tables (~55 lines) moved to vlib,
  where they are oracle-tested across every rollover.
- The timerfd declarations come with `import time`: no local fn C.
  decls, and arm_periodic builds a typed C.itimerspec instead of a raw
  [4]i64; the tick drains into a named u64 expiration count.
- date_line_len stays a literal 37: a fixed-array size computed from
  another module's const trips the checker in _test.v builds — the
  relationship to time.http_header_len is pinned by a test instead.
- New README with a mermaid flow of the whole model (one loop, two
  event kinds), the byte layout of the cached line, the cost table and
  the contrast with date_header/efficient_date.

Verified on a patched toolchain: 3/3 tests, -prod build, live server
with Date advancing under zero load.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant